在 分布式版本控制系统中,不存在 Git 强制所有人依赖的单一中央仓库。相反,协作是一种社会约定,而非技术上的强制要求。本课将介绍 补丁工作流,这是像 Linux 内核这类高完整性项目所遵循的黄金标准。
1. 补丁的定义
一个 补丁 是向另一位开发者发送单个提交的方式。它是一个纯文本文件,通常用于共享提交内容,而无需共享整个分支或向服务器提供写入权限。
2. 补丁工作流示意图
在此模型中,开发人员独立工作,并将其贡献发送给项目维护者(集成者)。
3. 集成者模型
项目完整性由指定的负责人通过筛选贡献来维护。开发者生成补丁并通过 邮件发送。集成者在私有环境中审查这些补丁,然后执行 推送 到 官方仓库,确保每一行代码都经过审查。
main.py
TERMINALbash — 80x24
> Ready. Click "Run" to execute.
>
QUESTION 1
In a distributed version control system, why is the 'official repository' considered a social convention?
Because Git technically forces every user to use a central server.
Because every contributor holds a full-fidelity history, making any repo potentially 'central'.
Because it is the only place where the .git folder exists.
Because patches cannot be applied to local repositories.
✅ Correct!
Exactly. Git is peer-to-peer; the 'official' status is simply an agreement among the developers.❌ Incorrect
Git does not force a central server. Every developer's local copy is a complete repository.QUESTION 2
Which of the following best defines a 'patch' in Git?
A full backup of the entire project database.
A way to share specific commits without needing shared access to a branch.
A command that deletes experimental code.
An encrypted key used for SSH authentication.
✅ Correct!
Correct! Patches serialize a commit into a text file that can be sent via email.❌ Incorrect
Patches are focused on individual changes (commits), not the whole project or security keys.QUESTION 3
What is the primary role of the 'Integrator' in the patch workflow?
To write the majority of the project's source code.
To act as a gatekeeper, reviewing and applying patches to the official repository.
To host the mailing list server.
To automatically merge all incoming emails into the master branch.
✅ Correct!
The integrator ensures code quality by reviewing patches before they reach the main history.❌ Incorrect
The integrator is a human gatekeeper, not an automated script or a server host.QUESTION 4
Which command is typically used to create these portable commit files?
git push --patchgit format-patchgit send-commitgit commit --export✅ Correct!
git format-patch is the standard command for generating email-ready patch files.❌ Incorrect
git format-patch is the correct tool for this specific serialization.QUESTION 5
In the diagram provided, what is the action taken by the Developer toward the Official Repository?
Push
Pull
Format
Review
✅ Correct!
Developers 'Pull' from the official repo to stay updated; they do NOT 'Push' directly to it in this workflow.❌ Incorrect
In a patch workflow, developers do not have push access; they pull changes to stay in sync.Case Study: The Linux Kernel Model
Decentralized Collaboration Governance
You are the maintainer of a popular open-source library. To prevent low-quality code from entering the master branch, you decide to move away from a 'Shared Central Repo' model to an 'Integrator' model.
Q
Why would an email-based patch workflow be superior for a project with thousands of global contributors who don't know each other?
Solution:
It allows for rigorous asynchronous review. Contributors don't need 'write access' (which is a security risk), and every change is forced through a gatekeeper (the maintainer) who can audit the logic before it becomes part of the permanent history.
It allows for rigorous asynchronous review. Contributors don't need 'write access' (which is a security risk), and every change is forced through a gatekeeper (the maintainer) who can audit the logic before it becomes part of the permanent history.
Q
What is the difference between a developer's local repository and the 'official' repository in this scenario?
Solution:
Technically, they are identical distributed repositories. Socially, the 'official' repository is simply the one the community agrees to treat as the source of truth, usually managed by the lead integrator.
Technically, they are identical distributed repositories. Socially, the 'official' repository is simply the one the community agrees to treat as the source of truth, usually managed by the lead integrator.